<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class BalanceHistory extends BaseModel
{
    use HasFactory;
    protected $table = 'balance_history';
    // 允许批量操作的字段
    protected $fillable = [
        'date',
        'customer_id',
        'amount',
        'business',
        'business_id',
        'detail',
        'created_at',
        'updated_at'
    ];
    public function scopeSearch($query,$params)
    {
        if(!empty($params['business'])){
            $query->where('business',$params['business']);
        }
        if(!empty($params['customer_id'])){
            $query->where('customer_id',$params['customer_id']);
        }
        return $query;
    }

    public function customer(){
        return $this->hasOne(Customer::class,'id','customer_id');
    }

    public function order(){
        return $this->hasOne(Order::class,'id','business_id');
    }




}


